package com.example.java_gobang.config;

import com.example.java_gobang.api.GameApi;
import com.example.java_gobang.api.MatchApi;
import com.example.java_gobang.api.TestApi;
import com.example.java_gobang.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.HandshakeInterceptor;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    @Autowired
    private TestApi testApi;
    @Autowired
    private MatchApi matchApi;
    @Autowired
    private GameApi gameApi;
    @Autowired
    private LoginInterceptor loginInterceptor;
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(testApi,"/test");
        registry.addHandler(matchApi,"/findMatch")
                .addInterceptors(new HttpSessionHandshakeInterceptor());
        registry.addHandler(gameApi,"/game")
                .addInterceptors(new HttpSessionHandshakeInterceptor());
    }
}
